package cn.ml.gaoJi.api.array;
import java.util.Scanner;

public class CustomerBiz {
	String[] names =new String[4];
	int i = 0;
	public void addName(String name) {
		if(i >= names.length) {
			return;
		}
		if(names[i] == null) {
			names[i] = name;
			i++;
		}
	}
	
	public void showNames() {
		for (String name:names){
			System.out.println(name+"  ");
		}
		/*for(int i=0;i<names.length;i++) {
			System.out.println(names[i]+"  ");
		}*/
	}
	
	public boolean editName (String oldName,String newName) {
		boolean find = false;
		for(int i=0;i<names.length;i++) {
			if(oldName != null && oldName.equals(names[i])) {
				names[i] = newName;
				find = true;
				break;
			}
		}
		return find;
	}


	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		String name;
		CustomerBiz cus = new CustomerBiz();
		for(int i=0;i<cus.names.length;i++) {
			System.out.println("请输入第"+(i+1)+"个姓名：");
			name = input.next();
			cus.addName(name);
		}
		cus.showNames();
		System.out.println("请输入需要修改的姓名：");
		String oldName = input.next();
		System.out.println("请输入新的姓名：");
		String newName = input.next();
		boolean find = cus.editName(oldName,newName);
		if(find) {
			System.out.println("有这个名字");
		}else {
			System.out.println("抱歉，没有这个名字");
		}
		cus.showNames();
	}

}
